package com.example.administrator.helloworld;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/3/16 0016.
 */
public class FruitActivity extends Activity {
    //private String[] dataArr = {"apple","banana","orange","watermelon","pear","grape","pineapple","strawberry","cherry","mango"};
    private List<Fruit> fruitList = new ArrayList<Fruit>();
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*requestWindowFeature(Window.FEATURE_NO_TITLE);*/
        setContentView(R.layout.fruit);//关联layout
        //this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        //传接上个Activity的值
        Intent intent = getIntent();
        final String data = intent.getStringExtra("extra_data");

        initFruits();
        FruitAdapter fa = new FruitAdapter(FruitActivity.this,R.layout.fruit_item,fruitList);//?

       // ArrayAdapter<String> adapter = new ArrayAdapter<String> (FruitActivity.this,android.R.layout.simple_list_item_1,dataArr);//?
        ListView listView = (ListView) findViewById(R.id.listView);
        listView.setAdapter(fa);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Fruit fruit = fruitList.get(position);//获取序数
                Toast.makeText(FruitActivity.this,fruit.getName(),Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initFruits() {
        Fruit apple = new Fruit("Apple",R.drawable.myface);
        fruitList.add(apple);
        Fruit banana = new Fruit("Banana",R.drawable.myface);
        fruitList.add(banana);
        Fruit orange = new Fruit("Orange",R.drawable.myface);
        fruitList.add(orange);
        Fruit watermelon = new Fruit("Watermelon",R.drawable.myface);
        fruitList.add(watermelon);
        Fruit pear = new Fruit("Pear",R.drawable.myface);
        fruitList.add(pear);
        Fruit grape = new Fruit("Grape",R.drawable.myface);
        fruitList.add(grape);
        Fruit pineapple = new Fruit("Pineapple",R.drawable.myface);
        fruitList.add(pineapple);
        Fruit strawberry = new Fruit("Strawberry",R.drawable.myface);
        fruitList.add(strawberry);
        Fruit cherry = new Fruit("Cherry",R.drawable.myface);
        fruitList.add(cherry);
        Fruit mango = new Fruit("Mango",R.drawable.myface);
        fruitList.add(mango);
    }

}
